//package com.shu.shiro;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.alibaba.druid.support.http.StatViewServlet;
//import com.alibaba.druid.support.http.WebStatFilter;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.boot.web.servlet.ServletRegistrationBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
//
//import javax.sql.DataSource;
//
//@Configuration
//public class DruidConfiguration {
//    @Bean
//    public ServletRegistrationBean statViewServlet(){
//        ServletRegistrationBean servletRegistrationBean =new ServletRegistrationBean(new StatViewServlet());
//        //白名单
//        servletRegistrationBean.addInitParameter("allow","127.0.0.1");
//        //ip黑名单（存在共同时，deny优先于allow）
//        //servletRegistrationBean.addInitParameter("deny","192.168.31.32");
//        servletRegistrationBean.addInitParameter("loginUsername","admin");
//        servletRegistrationBean.addInitParameter("loginPassword","admin");
//        //是否能够重置数据
//        servletRegistrationBean.addInitParameter("resetEnable","false");
//        return servletRegistrationBean;
//    }
//    @Bean
//    public FilterRegistrationBean statFilter(){
//        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
//        //添加过滤规则
//        filterRegistrationBean.addUrlPatterns("/*");
//        //不需要忽略的格式信息
//        filterRegistrationBean.addInitParameter("exclusions","*.js,*.css,*.jpg,*.png,*.ico,*.gif,/druid/*");
//        return filterRegistrationBean;
//    }
//    @Bean
//    PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor(){
//        return new PersistenceExceptionTranslationPostProcessor();
//    }
//
//    @Bean(name = "dataSource")
//    @Primary
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DataSource dataSource(){
//        return DataSourceBuilder.create().type(DruidDataSource.class).build();
//    }
//
//
//    @Bean
//    public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception{
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//        sqlSessionFactoryBean.setDataSource(dataSource());
//        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//        sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapper/*.xml"));
//        return sqlSessionFactoryBean;
//    }
//}
